package com.ruima.study.jdk21.demo1;

public class Demo1Switch {
    public static void main(String[] args) {
        String name = "bb";

        String  count = switch (name) {
            case "aa","bb" -> "三国";
            case "dd","zz" -> "hanchu";
            default -> "wei";
        };
        System.out.println("11111111111111111111111" + count);


        int byJDK17 = getByJDK17(Week.FRIDAY);
        System.out.println(byJDK17);


    }


    /**
     * 在JDK17中获取switch返回值
     *
     * @param week
     * @return
     */
    public static int getByJDK17(Week week) {
        // 1, 现在的switch变成了表达式，可以返回值了，而且支持yield和->符号来返回值
        // 2, 再也不用担心漏写了break，而导致出问题了
        // 3, case后面支持写多个条件
        return switch (week) {
            case MONDAY -> 1;
            case TUESDAY -> 2;
            case WEDNESDAY -> 3;
            case THURSDAY -> {yield 4;}
            case FRIDAY -> 5;
            case SATURDAY, SUNDAY -> 6;
            default -> 0;
        };
    }


    /**
     * 在JDK8中获取switch返回值方式
     *
     * @param week
     * @return
     */
    public static int getByJDK8(Week week) {
        int i = 0;
        switch (week) {
            case MONDAY, TUESDAY:
                i = 1;
                break;
            case WEDNESDAY:
                i = 3;
                break;
            case THURSDAY:
                i = 4;
                break;
            case FRIDAY:
                i = 5;
                break;
            case SATURDAY:
                i = 6;
                break;
            case SUNDAY:
                i = 7;
                break;
            default:
                i = 0;
                break;
        }

        return i;
    }


    private enum Week {
        MONDAY,
        TUESDAY,
        WEDNESDAY,
        THURSDAY,
        FRIDAY,
        SATURDAY,
        SUNDAY
    }

}


